
#pragma once

#include <ttg/all.h>
#include "Sphere.h"

using namespace ttg::pipeline;

//Tests pipeine on unintersected spheres.
bool pipelineTest1(Pipeline<std::vector<Sphere> *, float> &pl,
				   double &t_elapsed)
{
	//Creating unintersected spheres.
	std::vector<Sphere> spheres(4 * 1024);
	for (size_t i = 0; i < spheres.size(); i++)
	{
		spheres[i].radius = 1.0f;
		spheres[i].center = ttg::math::vec3f(3.0f * i, 0.0f, 0.0f);
	}
	//Testing.
	double t_start = ttg::services::Timer::getRef()->getSeconds();
	bool res = (pl.run(&spheres)[0] == 0.0f);
	double t_end = ttg::services::Timer::getRef()->getSeconds();
	//Returning result and elapsed time.
	t_elapsed = t_end - t_start;
	return res;
}

//Tests pipeline on array with equal spheres.
bool pipelineTest2(Pipeline<std::vector<Sphere> *, float> &pl,
				   double &t_elapsed)
{
	//Creating spheres with equal radius an center.
	std::vector<Sphere> spheres(5 * 1024);
	for (size_t i = 0; i < spheres.size(); i++)
	{
		spheres[i].radius = 1.0f;
		spheres[i].center = vec3f(0.0f, 0.0f, 0.0f);
	}
	//Testing.
	double t_start = ttg::services::Timer::getRef()->getSeconds();
	bool res = fabs(pl.run(&spheres)[0] / 5120 - (5 * 1024 - 1)) <= 0.5f;
	double t_end = ttg::services::Timer::getRef()->getSeconds();
	//Returning result and elapsed time.
	t_elapsed = t_end - t_start;
	return res;
}

//Tests pipeline on random spheres.
bool pipelineTest3(Pipeline<std::vector<Sphere> *, float> &pl,
				   double &t_elapsed)
{
	//Creating spheres with equal radius an center.
	std::vector<Sphere> spheres(1024);
	for (size_t i = 0; i < spheres.size(); i++)
	{
		spheres[i].radius = ttg::math::getFloatRandom(2.0f, 4.0f);
		spheres[i].center = ttg::math::vec3f(ttg::math::getFloatRandom(-16.0f, 16.0f),
											 ttg::math::getFloatRandom(-16.0f, 16.0f),
											 ttg::math::getFloatRandom(-16.0f, 16.0f));
	}
	//Testing.
	double t_start = ttg::services::Timer::getRef()->getSeconds();
	double depth = pl.run(&spheres)[0];
	bool res = (1.0f < depth && depth <= 4 * 1024 * 1024);
	double t_end = ttg::services::Timer::getRef()->getSeconds();
	//Returning result and elapsed time.
	t_elapsed = t_end - t_start;
	return res;
}
